import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class db_util_parser {
	public String sQuery = "";
	public String sValue = "";
	private String[] oTokens = null;
	
	db_util_parser (String[] oTokenList){
		oTokens = oTokenList;
	}
	
	public void restart(String sQueryStr) {
		sValue = "";
		sQuery = sQueryStr;
	}
	
	public  boolean matchReplaceNoSpace(String sRep, String sComp) {
	
		if (sRep.toUpperCase().startsWith(sComp)) {
		
			sQuery = sRep.substring(sComp.length(), sRep.length()).trim();
			sValue = sComp;
			return true;
		}
		return false;
	}

	public  boolean matchReplace(String sRep, String sComp) {
		
		if (sRep.toUpperCase().startsWith(sComp + " ")) {
			sQuery = sRep.substring(sComp.length(), sRep.length()).trim();
			sValue = sComp;
			return true;
		}

		return false;
	}
	public boolean matchReplace(String sRep, Pattern sComp) {
		
		// Very very very bad for performance
		for (int i = 0; i < oTokens.length; i++)
			if (sQuery.startsWith(oTokens[i] + " "))
				return false;
		
		Matcher ma = sComp.matcher(sRep);
		if (ma.find() && ma.start() == 0) {
			
			sValue = ma.group();
			sQuery = sRep.substring(ma.group().length(), sRep.length()).trim();
			return true;
		}
		return false;
	}	
}
